﻿using System;
using kunukn.RecommendationEngine.AreaRecommendation.Code.Entities;
using kunukn.RecommendationEngine.AreaRecommendation.Code.Helpers;
using kunukn.RecommendationEngine.AreaRecommendation.Code.Web;


namespace kunukn.RecommendationEngine.AreaRecommendation.Controls
{
    /// <summary>
    /// Author: Kunuk Nykjaer
    /// </summary>
    public partial class DataView : MyControl
    {
        public bool EnableEdit { get; set; } 

        protected void Page_Load(object sender, EventArgs e)
        {
            btnClearI2I.Visible = EnableEdit;

            matrix.Text = HtmlHelper.GetMatrix_Html(SessionHelper.GetItem2Item());          
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            Item currentItem = base.GetCurrentItem();

            if (!currentItem.IsValid())
            {
                panelMaxcount.Visible = false;
                panelCosine.Visible = false;
                panelJaccardIndex.Visible = false;
                panelVectors.Visible = false;               
            }
            else
            {
                var i2i = SessionHelper.GetItem2Item();
                maxcount.Text = HtmlHelper.GetMaxCount_Html(currentItem, i2i );
                cosine.Text = HtmlHelper.GetCosine_Html(currentItem, i2i);
                jaccard.Text = HtmlHelper.GetJaccardIndex_Html(currentItem, i2i);
                vectors.Text = HtmlHelper.GetVectors_Html(currentItem, i2i);
            }            
        }

        protected void btnClearI2I_Click(object sender, EventArgs e)
        {
            SessionHelper.GetItem2Item().Clear();
            Server.Transfer(Request.Path); //reload page
        }
    }
}